﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LakeSide.IService;
using LakeSide.DataAccess;
using LakeSide.Entity;
using MongoDB;

namespace LakeSide.Service
{
    public class AppInit:IAppInit
    {
        public string GetData()
        {
            MongoDatabase db = new MongoDatabase("mongodb://fred:foobar@localhost/test");
            
            return "1";
        }

        #region IAppInit 成员

        bool IAppInit.Init()
        {
            

            bool flag = false;
            using (var db =new Mongodb())
            {
                //先添加Action权限

                db.GetCollection<SE_User>().Insert(InitData.UserList);
                flag = true;
            }

            return flag;
        }

        bool IAppInit.IsInit()
        {
            bool flag = false;
            using (var db = new Mongodb())
            {
                //判断是否已经初始化
                if (db.CurrentDb.GetCollection <SE_User>().Count()>0)
                    flag = true;
            }
            return flag;
        }

        #endregion
    }
    public class InitData
    {
        /// <summary>
        /// Action权限
        /// </summary>
        public static List<SE_RightAction> RightActionList 
        {
            get
            {
                return new List<SE_RightAction>()
                {
                    new SE_RightAction(){ID="1",Action="Index"},    
                    new SE_RightAction(){ID="2",Action="Insert"},   
                    new SE_RightAction(){ID="3",Action="Update"},
                    new SE_RightAction(){ID="4",Action="Get"},
                    new SE_RightAction(){ID="5",Action="Delete"}    
                };
            }
        }

        /// <summary>
        /// Menu菜单
        /// </summary>
        public static List<SE_RightMenu> RightMenuList
        {
            get 
            { 
                return new List<SE_RightMenu>()
                {
                    new SE_RightMenu(){ID="1",Controller="Home",Action="Index"}
                };
            }
        }

        /// <summary>
        /// 角色
        /// </summary>
        public static List<SE_Role> RoleList
        {
            get 
            {
                return new List<SE_Role>()
                {
                    new SE_Role(){ID="1",Name="管理员"}
                };
            }
        }

        /// <summary>
        /// 用户
        /// </summary>
        public static List<SE_User> UserList
        {
            get
            {
                return new List<SE_User>()
                {
                    new SE_User(){ID="0",JobNumber="admin",Pwd="123456"}
                };
            }
        }

        

    }
}
